package com.dfbz.homework7;

import org.junit.Test;

import java.lang.reflect.Field;

public class main {
//    static Class<Student> clazz;
//     @BeforeClass
//     public static void before() {
//         clazz = Student.class;
//     }
        @Test
    public void test01() throws IllegalAccessException, InstantiationException, NoSuchFieldException {
        Class<Person> personClass = Person.class;
        Person person = personClass.newInstance();
        person.setName("张三");
//        不使用setAge方法直接使用反射方式对age赋
            Field ages = personClass.getDeclaredField("age");//获取所有的 包括公有私有
            ages.setAccessible(true);
            ages.set(person,20);
            person.show();
        }
}
